package com.gaussian.property.admin.module.biz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gaussian.property.admin.module.biz.service.CheckTableService;
import com.gaussian.property.admin.module.biz.vo.checktable.CheckTableVo;
import com.gaussian.property.admin.module.biz.vo.checktable.PageQueryCheckTableRequest;
import com.gaussian.property.module.biz.entity.CheckTable;
import com.songqi.common.core.domain.OptionVo;
import com.songqi.common.core.domain.R;
import com.songqi.common.core.domain.page.PageDataInfo;
import com.songqi.common.core.validationgroup.AddGroup;
import com.songqi.common.core.validationgroup.EditGroup;
import com.songqi.common.web.request.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.validation.groups.Default;
import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: songqi(13776346982)
 * @date: 2024/4/11 21:03
 */
@Api(tags = "稽核表管理操作")
@Validated
@RestController
@RequestMapping("checkTable/")
public class CheckTableController extends BaseController {

    @Resource
    private CheckTableService checkTableService;


    @ApiOperation("分页查询稽核表（稽核标准）")
    @GetMapping("/pageQueryCheckTable")
    public R<PageDataInfo<CheckTable>> pageQueryCheckTable(PageQueryCheckTableRequest queryRequest) {
        IPage<CheckTable> pageData = checkTableService.pageQueryCheckTable(queryRequest);
        return getReturnDataTableInfo(pageData);
    }

    @ApiOperation("查询稽核表（稽核标准）下拉选项")
    @PostMapping("/listCheckTableOptions")
    public R<List<OptionVo>> listCheckTableOptions() {
        List<OptionVo> optionVoList = new ArrayList<>();
        List<CheckTable> list = checkTableService.list();
        for (CheckTable checkTable : list) {
            OptionVo optionVo = new OptionVo();
            optionVo.setName(checkTable.getCheckName());
            optionVo.setValue(checkTable.getCheckTableId());
            optionVoList.add(optionVo);
        }
        return R.success(optionVoList);
    }


    @ApiOperation("新增稽核表（稽核标准）")
    @PostMapping("/add")
    public R<Void> add(@RequestBody @Validated({Default.class}) CheckTableVo addCheckTable) {
        checkTableService.addCheckTable(addCheckTable);
        return R.ok();
    }



    @ApiOperation("编辑稽核表（稽核标准）")
    @PostMapping("/edit")
    public R<Void> edit(@Validated({EditGroup.class, Default.class})@RequestBody CheckTableVo editCheckTable) {
        checkTableService.editCheckTable(editCheckTable);
        return R.ok();
    }

    @ApiOperation("删除稽核表（稽核标准）")
    @PostMapping("/del/{checkTableId}")
    public R<Void> del(@ApiParam("稽核表id") @PathVariable String checkTableId) {
        checkTableService.delCheckTable(checkTableId);
        return R.ok();
    }

    @ApiOperation("查看稽核表（稽核标准）详情")
    @GetMapping("/viewDetail/{checkTableId}")
    public R<CheckTableVo> viewDetail(@ApiParam("稽核表id") @PathVariable String checkTableId){
        return R.success(checkTableService.viewDetail(checkTableId));
    }

    @ApiOperation("导入稽核表")
    @PostMapping("/importCheckTable")
    public R<Void> importCheckTable(@RequestPart MultipartFile file) {
        checkTableService.importCheckTableExcel(file);
        return R.success();
    }


}
